/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including but not limited to the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to provide persons with access to the Software
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGE OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import downIcon from "../../assets/images/down.png";
import shareIcon from "../../assets/images/share.svg";
import "./index.less";
import { useInteraction } from "../../utils/useInteraction";
import { PointerState } from "@hadss/web_uni_input";

interface DetailNavProps {
  deviceType?: string;
  isPlay?: string;
  musicId?: number;
}

const DetailNav: React.FC<DetailNavProps> = (props) => {
  const navigate = useNavigate();
  const [showShareMenu, setShowShareMenu] = useState(false);

  const goRetreat = () => {
    navigate(`/musicList?musicId=${props.musicId}`);
  };

  const onLongPress = (e: PointerState) => {
    setShowShareMenu(true);
  };

  const longPressRef = useInteraction({
    handlers: {
      onLongPressStart: (e: any) => onLongPress(e),
    },
    configs: {
      enableLongPress: true,
    },
  });

  const handleShare = (platform: string) => {
    // 处理分享逻辑
    console.log(`分享到${platform}`);
    setShowShareMenu(false);
  };

  return (
    <div className="head-detail-nav">
      <img onClick={goRetreat} src={downIcon} alt="返回" />
      {props.deviceType === "mobile" && (
        <div className="nav_tab">
          <span></span>
          <span></span>
        </div>
      )}
      <div className="share-container">
        <img ref={longPressRef as any} src={shareIcon} alt="分享" />
        {showShareMenu && (
          <div className="share-menu">
            <div className="menu-overlay" onClick={() => setShowShareMenu(false)} />
            <div className="menu-content">
              <div className="menu-item" onClick={() => handleShare('wechat')}>
                分享此歌曲
              </div>
            </div>
          </div>
        )}
      </div>
    </div>
  );
};

export default DetailNav;